#!/bin/sh

ROOTPATH=${PWD}
echo "ROOTPATH:${ROOTPATH}"

#if [ $# == 0 ]; then exit -1; fi
param=$1

rgiskardpath=$ROOTPATH/rgiskard
echo $rgiskardpath

if [ "$param" == "kernel" ]; then
  cd $rgiskardpath
  make ARCH=arm64  CROSS_COMPILE=aarch64-linux-gnu- Image
fi

matrixpath=$ROOTPATH/minimatrix
echo $matrixpath

buildmatrixpath=/tmp/buildmatrix
if [ "$param" == "matrix" ]; then
  mkdir -p $buildmatrixpath
  rm -rf $buildmatrixpath/*
  cd $buildmatrixpath
  $matrixpath/configure --target-list=aarch64-softmmu --enable-debug
  make
fi

if [ ! -f $rgiskardpath/arch/arm64/boot/Image ]; then
  echo "no $buildmatrixpath/aarch64-softmmu/qemu-system-aarch64"
  echo "run $0 kernel"
  exit -1
fi

if [ ! -f $buildmatrixpath/aarch64-softmmu/qemu-system-aarch64 ]; then
  echo "no $buildmatrixpath/aarch64-softmmu/qemu-system-aarch64"
  echo "run $0 matrix"
  exit -1
fi

echo ""
echo "$buildmatrixpath/aarch64-softmmu/qemu-system-aarch64 -machine virt -cpu cortex-a57 -m 256M -kernel $rgiskardpath/arch/arm64/boot/Image -nographic -d out_asm,in_asm,op"
